#include <iostream>
using namespace std;

int main() {
  auto rexp = [](auto &self) -> int {
    int cnt = 0;
    char ch;
    while (cin >> ch) {
      if (ch == 'a') cnt++;
      if (ch == '(') cnt += self(self);
      if (ch == ')') return cnt;
      if (ch == '|') return max(cnt, self(self));
    }
    return cnt;
  };

  cout << rexp(rexp) << endl;
}